package com.example.lib_audio.audio

import android.media.MediaPlayer
import android.media.MediaPlayer.OnCompletionListener
import android.util.Log
import com.example.lib_audio.eventbus.AudioLoadEvent
import org.greenrobot.eventbus.EventBus

class StateMediaPlayer:MediaPlayer(),OnCompletionListener {
    private var currentState = MediaPlayerState.IDLE

    init {
        setOnCompletionListener(this)
    }


    //获取当前状态
    fun getStatus() = currentState

    override fun reset() {//空闲
        super.reset()
        currentState = MediaPlayerState.IDLE
    }

    override fun setDataSource(path: String?) {//初始化状态
        super.setDataSource(path)
        currentState = MediaPlayerState.INITIATE
    }

    override fun start() {//启动
        super.start()
        currentState = MediaPlayerState.START
    }

    override fun pause() {//暂停
        super.pause()
        currentState = MediaPlayerState.PAUSE
    }


    override fun stop() {//停止
        super.stop()
        currentState = MediaPlayerState.STOP
    }



    override fun setOnPreparedListener(listener: OnPreparedListener?) {//准备完成
        super.setOnPreparedListener(listener)
        currentState = MediaPlayerState.PREPARED

    }

    override fun onCompletion(mp: MediaPlayer?) { //结束
        currentState = MediaPlayerState.COMPLETION
    }



    enum class MediaPlayerState{
        IDLE,INITIATE,START,PAUSE,STOP,PREPARED,COMPLETION
    }
}